package com.beagle.njddapp.weight.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.beagle.njddapp.R;
import com.beagle.njddapp.bean.owner.NjAndOilBean;
import com.beagle.njddapp.bean.owner.NjBean;
import com.beagle.njddapp.bean.owner.OilOrderBean;
import com.blankj.utilcode.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-13 20:13
 * ..农机加油订单 评价
 */
public class NjOilPjDIalog extends Dialog {

    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_chepai)
    TextView tvCp;
    @BindView(R.id.iv1)
    ImageView iv1;
    @BindView(R.id.iv2)
    ImageView iv2;
    @BindView(R.id.iv3)
    ImageView iv3;
    @BindView(R.id.iv4)
    ImageView iv4;
    @BindView(R.id.iv5)
    ImageView iv5;
    private NjAndOilBean njAndOilBean;
    private OilOrderBean oilOrderBean;

    private List<Boolean> plList;
    private NjOilPlCallBack njOilPlCallBack;

    public void setNjOilPlCallBack(NjOilPlCallBack njOilPlCallBack) {
        this.njOilPlCallBack = njOilPlCallBack;
    }

    public NjOilPjDIalog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_nj_oilorder_pl);
        ButterKnife.bind(this);
        if (getWindow() != null) {
            //按空白处不能取消动画
            setCanceledOnTouchOutside(true);
            //设置window背景，默认的背景会有Padding值，不能全屏。当然不一定要是透明，你可以设置其他背景，替换默认的背景即可。
            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            //一定要在setContentView之后调用，否则无效
            getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            getWindow().setWindowAnimations(R.style.DialogAnim);
        }
        plList=new ArrayList<>();
        plList.add(true);
        plList.add(true);
        plList.add(true);
        plList.add(true);
        plList.add(true);

    }
    public void update( NjAndOilBean njAndOilBean) {
        this.njAndOilBean = njAndOilBean;
        tvNumber.setText("加油订单"+njAndOilBean.getOrderNum());
        tvName.setText(njAndOilBean.getExpectMeter()+" L");
        tvCp.setText(njAndOilBean.getTotalAmount()+" 元");

//            tvYUan.setVisibility(View.VISIBLE);
//            tvPrice.setText(oilOrderBean.getAmount());


    }

    public void update( OilOrderBean oilOrderBean) {
        this.oilOrderBean = oilOrderBean;
        tvNumber.setText("加油订单"+oilOrderBean.getOrderNum());
        tvName.setText(oilOrderBean.getExpectMeter()+" L");
        tvCp.setText(oilOrderBean.getTotalAmount()+" 元");

//            tvYUan.setVisibility(View.VISIBLE);
//            tvPrice.setText(oilOrderBean.getAmount());


    }
    @OnClick({R.id.container, R.id.tv_exit,R.id.tv_fk,R.id.iv1,R.id.iv2,R.id.iv3,R.id.iv4,R.id.iv5,R.id.iv_close})
    public void onCLick(View view) {
        switch (view.getId()) {
            case R.id.container:
            case R.id.iv_close:
                dismiss();
                break;
            case R.id.tv_exit:
                int i=0;
                for (Boolean b:plList){
                    if (b){
                        i++;
                    }
                }
                if (i==0){
                    ToastUtils.showShort("评价最少一星哦");
                    return;
                }
                dismiss();
                if (njAndOilBean!=null){
                    njOilPlCallBack.oilPl(njAndOilBean.getOrderId(),i);
                }else if (oilOrderBean!=null){
                    njOilPlCallBack.oilPl(oilOrderBean.getOrderId(),i);
                }
                break;
            case R.id.tv_fk:
                dismiss();
                njOilPlCallBack.toSuggest();
                break;
            case R.id.iv1:
                if (plList.get(0)){
                    ToastUtils.showShort("评价最少一星哦");
                }else {
                    iv1.setImageResource(R.mipmap.score_star);
                    iv2.setImageResource(R.mipmap.score_star_nor);
                    iv3.setImageResource(R.mipmap.score_star_nor);
                    iv4.setImageResource(R.mipmap.score_star_nor);
                    iv5.setImageResource(R.mipmap.score_star_nor);
                    plList.set(0,true);
                    plList.set(1,false);
                    plList.set(2,false);
                    plList.set(3,false);
                    plList.set(4,false);
                }
                break;
            case R.id.iv2:
                if (plList.get(1)){
                    plList.set(1,false);
                    plList.set(2,false);
                    plList.set(3,false);
                    plList.set(4,false);
                    iv2.setImageResource(R.mipmap.score_star_nor);
                    iv3.setImageResource(R.mipmap.score_star_nor);
                    iv4.setImageResource(R.mipmap.score_star_nor);
                    iv5.setImageResource(R.mipmap.score_star_nor);
                }else {
                    plList.set(0,true);
                    plList.set(1,true);
                    iv1.setImageResource(R.mipmap.score_star);
                    iv2.setImageResource(R.mipmap.score_star);
                    iv3.setImageResource(R.mipmap.score_star_nor);
                    iv4.setImageResource(R.mipmap.score_star_nor);
                    iv5.setImageResource(R.mipmap.score_star_nor);
                }
                break;
            case R.id.iv3:
                if (plList.get(2)){
                    plList.set(2,false);
                    plList.set(3,false);
                    plList.set(4,false);
                    iv3.setImageResource(R.mipmap.score_star_nor);
                    iv4.setImageResource(R.mipmap.score_star_nor);
                    iv5.setImageResource(R.mipmap.score_star_nor);
                }else {
                    plList.set(0,true);
                    plList.set(1,true);
                    plList.set(2,true);
                    iv1.setImageResource(R.mipmap.score_star);
                    iv2.setImageResource(R.mipmap.score_star);
                    iv3.setImageResource(R.mipmap.score_star);
                    iv4.setImageResource(R.mipmap.score_star_nor);
                    iv5.setImageResource(R.mipmap.score_star_nor);
                }
                break;
            case R.id.iv4:
                if (plList.get(3)){
                    plList.set(3,false);
                    plList.set(4,false);
                    iv4.setImageResource(R.mipmap.score_star_nor);
                    iv5.setImageResource(R.mipmap.score_star_nor);
                }else {
                    plList.set(0,true);
                    plList.set(1,true);
                    plList.set(2,true);
                    plList.set(3,true);
                    iv1.setImageResource(R.mipmap.score_star);
                    iv2.setImageResource(R.mipmap.score_star);
                    iv3.setImageResource(R.mipmap.score_star);
                    iv4.setImageResource(R.mipmap.score_star);
                    iv5.setImageResource(R.mipmap.score_star_nor);
                }
                break;
            case R.id.iv5:
                if (plList.get(4)){
                    plList.set(4,false);
                    iv5.setImageResource(R.mipmap.score_star_nor);
                }else {
                    plList.set(0,true);
                    plList.set(1,true);
                    plList.set(2,true);
                    plList.set(3,true);
                    plList.set(4,true);
                    iv1.setImageResource(R.mipmap.score_star);
                    iv2.setImageResource(R.mipmap.score_star);
                    iv3.setImageResource(R.mipmap.score_star);
                    iv4.setImageResource(R.mipmap.score_star);
                    iv5.setImageResource(R.mipmap.score_star);
                }
                break;
        }
    }

    public interface NjOilPlCallBack{
        void toSuggest();
        void oilPl(long  id, int pl );
    }

}
